﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class LoggingSection : DmsSectionWithDescription
{
    private DmsProperty? _aliasProperty;
    private DmsProperty? _fileSizeProperty;


    private DmsProperty? _groupProperty;
    private DmsProperty? _pathProperty;

    internal LoggingSection(SyntaxToken declareKeywordToken, Identifier name, StringLiteral? description,
        SyntaxNode? parent) :
        base(SyntaxKinds.LoggingSection, declareKeywordToken, name, description, parent)
    {
    }


    /// <summary>
    ///     Group = "Group"
    /// </summary>
    public DmsProperty? GroupProperty => _groupProperty;


    /// <summary>
    ///     Path = "Path"
    /// </summary>
    public DmsProperty? PathProperty => _pathProperty;


    /// <summary>
    ///     Alias = "Alias"
    /// </summary>
    public DmsProperty? AliasProperty => _aliasProperty;


    /// <summary>
    ///     [FileSize = FileSize]
    /// </summary>
    public DmsProperty? FileSizeProperty => _fileSizeProperty;


    public LoggingSection Update(DmsProperty? group, DmsProperty? path,
        DmsProperty? alias, DmsProperty? fileSize)
    {
        SetChildNullableField(ref _groupProperty, group);
        SetChildNullableField(ref _pathProperty, path);
        SetChildNullableField(ref _aliasProperty, alias);
        SetChildNullableField(ref _fileSizeProperty, fileSize);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, NameIdentifier, Description,
            GroupProperty, PathProperty, AliasProperty, FileSizeProperty);
    }
}


public static partial class NodeFactory
{
    public static LoggingSection CreateLoggingSection(SyntaxNode? parent, SyntaxToken declareKeywordToken,
        Identifier identifierName, StringLiteral? description, DmsProperty? group,
        DmsProperty? path, DmsProperty? alias, DmsProperty? fileSize)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.LoggingKeywordToken));
        LoggingSection section = new(declareKeywordToken, identifierName, description, parent);
        return section.Update(group, path, alias, fileSize);
    }
}